<template>
	<view>
		<view class="l1" v-for="item in list">
			<image :src="'http://124.93.196.45:10001'+item.imgUrl"></image>
			<text>{{item.name}}</text>
			<text>类别：{{item.type.name}}</text>
			<text>发布组织：{{item.author}}</text>
			<text>发起时间：{{item.activityAt}}</text>
			<view class="l2">
				<text>参与人数：{{item.donateCount}}次</text>
				<text>已筹善款：{{item.moneyNow}}元</text>
			</view>
			<u-button type="error" text="捐款" @click="key=true,id=item.id" style="width: 100px; margin-top: 20px;"></u-button>
		</view>
		<u-popup mode="center" :show="key" :closeable="true" @close="key=false">
			<view class="l3">
				<text>请输入你要捐款的金额：</text>
				<input v-model="money" placeholder="金额"/>
			</view>
			<u-button type="primary" text="确认" style="width: 100px; margin-top: 20px;" @click="juan"></u-button>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				id:0,
				key:false,
				money:''
			}
		},
		onLoad(options) {
			this.id=options.id
			this.getlist()
		},
		methods: {
			getlist(){
				this.api.get('/prod-api/api/public-welfare/public-welfare-activity/list?typeId='+this.id).then(res=>{
					this.list=res.data.rows
				})
			},
			juan(){
				if(this.money===''){
					uni.showToast({
						title:'金额为0',
						icon:'error'
					})
					return
				}
				const data={
					activityId:this.id,
					donateMoney:this.money
				}
				this.api.get('/prod-api/api/public-welfare/donate-record','POST',data).then(res=>{
					console.log(this.id)
					console.log(res.data)
					if(res.data.code===200){
						setTimeout(function(){
							uni.showToast({
								title:'捐款成功'
							})
						},700)
						this.key=false
					}else{
						uni.showToast({
							title:'捐款失败',
							icon:'error'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.l1{
	line-height: 30px;
	margin-top: 20px;
	display: flex;
	flex-direction: column;
	image{
		width: 100%;
		height: 175px;
	}
	.l2{
		display: flex;
		justify-content: space-between;
	}
}
.l3{
	margin-top: 20px;
	margin-bottom: 20px;
	display: flex;
}
</style>
